The EVALUATE
statement allows implementing case structures in Cobol. Each case is managed by a WHEN
phrase activated by
specific test of a variable.The WHEN OTHER
phrase allows managing all the cases which have not been taken into account by the previous
WHEN
phrases. If the variable to be tested contains a new value that is not currently managed then the absence of the WHEN
OTHER
phrase will lead a situation in which no process will be performed for this value and the program may have uncontrolled or undefined
behavior.
Noncompliant code example
A010-PRINCIPAL.
EVALUATE Y5FTAR-PER-ECN-CTS
WHEN '01'
MOVE 'A' TO WS-CD-PER-CTS
WHEN '02'
MOVE 'S' TO WS-CD-PER-CTS
WHEN '04'
MOVE 'T' TO WS-CD-PER-CTS
WHEN '12'
MOVE 'M' TO WS-CD-PER-CTS
END-EVALUATE.
Compliant solution
A010-PRINCIPAL.
EVALUATE Y5FTAR-PER-ECN-CTS
WHEN '01'
MOVE 'A' TO WS-CD-PER-CTS
WHEN '02'
MOVE 'S' TO WS-CD-PER-CTS
WHEN '04'
MOVE 'T' TO WS-CD-PER-CTS
WHEN '12'
MOVE 'M' TO WS-CD-PER-CTS
WHEN OTHERS
MOVE 'O' TO WS-CD-PER-CTS
END-EVALUATE.